package applets;

import java.awt.Color;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.border.LineBorder;

import wheel.KeyWheel;

public class ButtonWheel {

    final KeyWheel wheel;
    final int wheelId;
    
    JButton button,newButton;
    final char key;
    Font font;
    Color background;
    Color foreground;
    
    ButtonWheel previous;
    
    /**
     * The pin is active for this key.
     */
    boolean isEffective=false;
    /**
     * The arm use this key to be in contact with the lungs.
     */
    boolean isActiveKey;
    /**
     * The key is the selected one on the external vector.
     */
    boolean isSeenKey;
    
    
    /**
     * @param wheel
     * @param key
     */
    public ButtonWheel(KeyWheel wheel, char key) {
	this.wheel = wheel;
	this.key = key;
	this.wheelId= wheel.getId();
	this.button = new JButton(new StringBuilder().append(key).toString());
	button.setSize(50, 50);
    }

    public void actualize(){
	button=newButton;
	button.setBackground(background);
	button.setForeground(foreground);
	button.setFont(font);
	button.setText(new StringBuilder().append(key).toString());
    }
    
    /**
     * @return the next
     */
    public ButtonWheel getPrevious() {
        return previous;
    }

    public void giveToNext(){
	previous.setNewButton(button);
    }

    /**
     * @param next the next to set
     */
    public void setPrevious(ButtonWheel next) {
        this.previous = next;
    }


    /**
     * @return the button
     */
    public JButton getButton() {
        return button;
    }


    /**
     * @param button the button to set
     */
    public void setButton(JButton button) {
        this.button = button;
    }

    /**
     * @param button the button to set
     */
    public void setNewButton(JButton button) {
        this.newButton = button;
    }

    /**
     * @return the font
     */
    public Font getFont() {
        return font;
    }


    /**
     * @param font the font to set
     */
    public void setFont(Font font) {
        this.font = font;
        button.setFont(font);
    }


    /**
     * @return the background
     */
    public Color getBackground() {
        return background;
    }


    /**
     * @param background the background to set
     */
    public void setBackground(Color background) {
	button.setBackground(background);
	if(background==M209Applet.ACTIVE_BG){
	    button.setBorder(new LineBorder(M209Applet.ACTIVE_BG,2));
	}else{
	    button.setBorder(new LineBorder(Color.BLACK,1));
	}
	
        this.background = background;
    }


    /**
     * @return the foreground
     */
    public Color getForeground() {
        return foreground;
    }


    /**
     * @param forground the foreground to set
     */
    public void setForeground(Color foreground) {
	button.setForeground(foreground);
        this.foreground = foreground;
    }


    /**
     * @return the isEffective
     */
    public boolean isEffective() {
        return isEffective;
    }


    /**
     * @param isEffective the isEffective to set
     */
    public void setEffective(boolean isEffective) {
        this.isEffective = isEffective;
    }


    /**
     * @return the isActiveKey
     */
    public boolean isActiveKey() {
        return isActiveKey;
    }


    /**
     * @param isActiveKey the isActiveKey to set
     */
    public void setActiveKey(boolean isActiveKey) {
        this.isActiveKey = isActiveKey;
    }


    /**
     * @return the isSeenKey
     */
    public boolean isSeenKey() {
        return isSeenKey;
    }


    /**
     * @param isSeenKey the isSeenKey to set
     */
    public void setSeenKey(boolean isSeenKey) {
        this.isSeenKey = isSeenKey;
    }


    /**
     * @return the wheel
     */
    public KeyWheel getWheel() {
        return wheel;
    }


    /**
     * @return the wheelId
     */
    public int getWheelId() {
        return wheelId;
    }


    /**
     * @return the key
     */
    public char getKey() {
        return key;
    }
    
    
    
}
